package com.prg.util;

import java.io.IOException;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.util.Properties;

/**
 * Created with IntelliJ IDEA.
 * User: Administrator
 * Date: 14-5-11
 * Time: 下午3:02
 * To change this template use File | Settings | File Templates.
 */
public class DBConnection {
    private static Connection conn = null;
    private static Properties props = null;

    static {
        props = new Properties();
        try {
            props.load(DBConnection.class.getResourceAsStream("/application.properties"));
        } catch (IOException e1) {
            e1.printStackTrace();
        }
        try {
            Class.forName(props.getProperty("jdbc.driver"));
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        }
    }

    public static Connection getConn() {
        try {
            conn = DriverManager.getConnection(props.getProperty("jdbc.url"), props.getProperty("jdbc.username"), props.getProperty("jdbc.password"));
            conn.setAutoCommit(false);
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return conn;
    }


    public void closeConn() {
        try {
            if (conn != null)
                conn.close();
        } catch (SQLException e) {
            e.printStackTrace();
        }

    }


}
